<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/xlsx.full.min.js"></script>
  <script src="../Scripts/crypto-js.js"></script>
  <script src="../Scripts/secret.js"></script>
  <title>MES设备台账统计报表</title>
</head>

<body>
  <div id="app" v-cloak>
    <!-- 报表标题 -->
    <vue2-report-header :title="'MES设备台账统计报表'"></vue2-report-header>
    <div style="padding: 10px;">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" :label-position="'left'" :rules="rules" ref="queryInfoRef"
        :disabled="formDisable">
        <el-form-item label="筛选时间:" prop="selectdate">
          <el-date-picker v-model="queryInfo.selectdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="getData">查询</el-button>
          <el-button type="primary" icon="el-icon-download" size="small">导出</el-button>
          <el-button type="primary" icon="el-icon-s-operation" size="small"
            @click="devicesMaintObj.dialogVisible = true">
            台账维护
          </el-button>
        </el-form-item>
      </el-form>

      <!-- 表格显示区 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border>
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column label="分厂" prop="factoryname" width="140"></el-table-column>
        <el-table-column label="MES机数量" prop="deviceqty" width="100"></el-table-column>
        <el-table-column label="在用数量" prop="inuseqty" width="100">
          <template slot-scope="scope">
            <el-link type="primary" @click="openDetail(scope.row,1)">{{scope.row.inuseqty}}</el-link>
          </template>
        </el-table-column>
        <el-table-column label="未用数量" prop="unuseqty" width="100">
          <template slot-scope="scope">
            <el-link type="primary" @click="openDetail(scope.row,2)">{{scope.row.unuseqty}}</el-link>
          </template>
        </el-table-column>
        <el-table-column label="设备利用率" prop="userate" width="100">
          <template slot-scope="scope" v-if="scope.row.userate">
            {{scope.row.userate}}%
          </template>
        </el-table-column>
        <el-table-column label="登录人数" prop="loginempcount" width="100"></el-table-column>
        <el-table-column label="登录频次" prop="loginfrequency" width="100"></el-table-column>
        <el-table-column label="报工频次" prop="reportfrequency" width="100"></el-table-column>
        <el-table-column label="人/机比" prop="renjibi" width="100"></el-table-column>
        <el-table-column label="人/频次" prop="renpinci" width="100"></el-table-column>
        <el-table-column label="报/机（日均）" prop="baojirijun" width="120"></el-table-column>
        <el-table-column label="平均登录" prop="avglogin" width="100"></el-table-column>
        <el-table-column label="正常使用数" prop="normaluse" width="100"></el-table-column>
        <el-table-column label="有效利用率" prop="validuserate" width="100">
          <template slot-scope="scope" v-if="scope.row.validuserate">
            {{scope.row.validuserate}}%
          </template>
        </el-table-column>
      </el-table>
      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>

    <!-- 设备台账维护 -->
    <el-dialog title="设备台账维护" :visible.sync="devicesMaintObj.dialogVisible" width="90%" :top="'20px'">
      <!-- 查询条件 -->
      <el-form :inline="true" :model="devicesMaintObj.queryInfo" :label-position="'left'">
        <el-form-item label="主制分厂:" prop="factoryid">
          <el-select v-model="devicesMaintObj.queryInfo.factoryname" placeholder="请选择分厂" clearable filterable>
            <el-option v-for="f in factoryList" :key="f.factoryname" :label="f.factoryname" :value="f.factoryname">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label='资产编号:'>
          <el-input v-model="devicesMaintObj.queryInfo.device_no"></el-input>
        </el-form-item>

        <el-form-item label='IP:'>
          <el-input v-model="devicesMaintObj.queryInfo.ip_address"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="handleDevicesDataSearch">查询</el-button>
          <el-button type="success" icon="el-icon-circle-plus-outline" size="small"
            @click="addDeviceObj.dialogVisible = true">添加</el-button>
          <el-button type="primary" icon="el-icon-upload2" size="small" @click="devicesImport.dialogVisible=true">导入台账
          </el-button>
          <el-button type="danger" icon="el-icon-delete" size="small" @click="deleteDeviceBatch">批量删除</el-button>
        </el-form-item>
      </el-form>

      <!-- 设备表格 -->
      <el-table :data="devicesMaintObj.dataList" stripe border v-loading="loading" v-loading.fullscreen.lock="loading"
        :element-loading-text="loadingText" element-loading-background="rgba(0,0,0,0.8)" height="640" ref="devicesData">
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column type="selection" width="50"></el-table-column>
        <el-table-column label="id" prop="id" width="100" v-if="false"></el-table-column>
        <el-table-column label="操作" width="200">
          <template slot-scope="scope">
            <el-button size="mini" icon="el-icon-edit" type="primary" @click="showUpdateDeviceDialog(scope.row)">修改
            </el-button>
            <el-button size="mini" icon="el-icon-delete" type="danger" @click="deleteDevice(scope.row.id)">删除
            </el-button>
          </template>
        </el-table-column>
        <el-table-column label="资产编号" prop="device_no" width="200"></el-table-column>
        <el-table-column label="所属分厂" prop="factoryname" width="160"></el-table-column>
        <el-table-column label="IP地址" prop="ip_address" width="100"></el-table-column>
        <el-table-column label="创建人" prop="createemployee" width="100"></el-table-column>
        <el-table-column label="创建时间" prop="createdate" width="160" :formatter="replaceDate"></el-table-column>
        <el-table-column label="修改人" prop="lastchangeemployee" width="100"></el-table-column>
        <el-table-column label="修改时间" prop="lastchangedate" width="160" :formatter="replaceDate"></el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination @size-change="handleDevicesSizeChange" @current-change="handleDevicesCurrentChange"
        :current-page="devicesMaintObj.queryInfo.currentPage" :page-sizes="[10,20,50]"
        :page-size="devicesMaintObj.queryInfo.pageSize" layout="prev,pager,next,jumper,sizes,total"
        :total="devicesMaintObj.total">
      </el-pagination>
    </el-dialog>

    <!-- 添加设备 -->
    <el-dialog title="添加设备" :visible.sync="addDeviceObj.dialogVisible" width="40%" @close="addDeviceClosed">
      <el-form :model="addDeviceObj.addForm" :rules="addDeviceObj.rules" ref="addDeviceRef" :inline="true"
        :label-position="'top'" lable-width="100px">
        <el-form-item label="所属分厂" prop="factoryname">
          <el-select v-model="addDeviceObj.addForm.factoryname" placeholder="请选择分厂" clearable filterable>
            <el-option v-for="f in factoryList" :key="f.factoryname" :label="f.factoryname" :value="f.factoryname">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="资产编号" prop="device_no">
          <el-input v-model="addDeviceObj.addForm.device_no"></el-input>
        </el-form-item>

        <el-form-item label="IP地址" prop="ip_address">
          <el-input v-model="addDeviceObj.addForm.ip_address"></el-input>
        </el-form-item>
      </el-form>
      <!-- 弹出窗底下按钮 -->
      <span slot="footer" class="dialog-footer">
        <el-button @click="addDeviceObj.dialogVisible = false" size="small">取消</el-button>
        <el-button type="primary" size="small" @click="addDevice">确定</el-button>
      </span>
    </el-dialog>

    <!-- 修改设备 -->
    <el-dialog title="修改设备" :visible.sync="updateDeviceObj.dialogVisible" width="40%" @close="updateDeviceClosed">
      <el-form :model="updateDeviceObj.updateForm" :rules="updateDeviceObj.rules" ref="updateDeviceRef" :inline="true"
        :label-position="'top'" lable-width="100px">
        <el-form-item label="唯一id">
          <el-input v-model="updateDeviceObj.updateForm.id" :disabled="true"></el-input>
        </el-form-item>

        <el-form-item label="所属分厂" prop="factoryname">
          <el-select v-model="updateDeviceObj.updateForm.factoryname" placeholder="请选择分厂" clearable filterable>
            <el-option v-for="f in factoryList" :key="f.factoryname" :label="f.factoryname" :value="f.factoryname">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="资产编号" prop="device_no">
          <el-input v-model="updateDeviceObj.updateForm.device_no"></el-input>
        </el-form-item>

        <el-form-item label="IP地址" prop="ip_address">
          <el-input v-model="updateDeviceObj.updateForm.ip_address"></el-input>
        </el-form-item>
      </el-form>
      <!-- 弹出窗底下按钮 -->
      <span slot="footer" class="dialog-footer">
        <el-button @click="updateDeviceObj.dialogVisible = false" size="small">取消</el-button>
        <el-button type="primary" size="small" @click="updateDevice">确定</el-button>
      </span>
    </el-dialog>

    <!-- 设备台账导入 -->
    <el-dialog title="设备台账导入" :visible.sync="devicesImport.dialogVisible" width="60%" :top="'20px'"
      @close="devicesImport.dataList = []">
      <el-form :inline="true" ref="devicesImportRef">
        <el-form-item>
          <el-upload action="" :before-upload="devicesImportBeforeUpload" :multiple="true" accept=".xls,.xlsx">
            <el-button slot="trigger" type="primary" size="small" icon="el-icon-upload">选择文件</el-button>
            <el-button type="success" size="small" icon="el-icon-success" @click="saveDevicesImportData">保存</el-button>
            <span style="color:red;font-weight:bold;margin-left: 10px;">内部系统，严禁上传涉密信息</span>
          </el-upload>
        </el-form-item>
      </el-form>
      <!-- 表格 -->
      <el-table :data="devicesImport.dataList" stripe border ref="devicesImportData" v-loading="loading"
        v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" height="640">
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column type="selection" width="50"></el-table-column>
        <el-table-column label="操作" width="80">
          <template slot-scope="scope">
            <el-button size="mini" icon="el-icon-delete" type="danger" @click="handleDelete(scope.$index, scope.row)">
            </el-button>
          </template>
        </el-table-column>
        <el-table-column label="唯一id" prop="id" v-if="false"></el-table-column>
        <el-table-column label="资产编号" prop="device_no" width="180" show-overflow-tooltip></el-table-column>
        <el-table-column label="所属分厂" prop="factoryname" width="80"></el-table-column>
        <el-table-column label="IP地址" prop="ip_address" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="校验结果" prop="islegel" width="100">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.islegel === 1" type="success">校验成功</el-tag>
            <el-tag v-else type="danger">校验失败</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="校验失败原因" prop="illegalreason">
          <template slot-scope="scope">
            <span style="color:red;font-weight:bold;" v-if="scope.row.islegel === 0">
              <i class="el-icon-warning"></i>
              {{scope.row.illegalreason}}
            </span>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <!-- 在用明细  -->
    <el-dialog :title="detail.title" :top="'10px'" :center="true" :visible.sync="detail.dialogVisiable">
      <el-table v-loading="detail.loading" v-loading.fullscreen.lock="detail.loading" style="height:700px"
        :element-loading-text="detail.loadingText" element-loading-background="rgba(0,0,0,0.8)" :data="detail.dataList"
        stripe border>
        <el-table-column type="index" min-width="50"></el-table-column>
        <el-table-column label="操作" min-width="200">
          <template slot-scope="scope">
            <el-button type="primary" icon="el-icon-download" size="mini" @click="exportInUseDevicesInfo">
              导出
            </el-button>
          </template>
        </el-table-column>
        <el-table-column label="分厂" prop="factoryname" min-width="120" show-overflow-tooltip></el-table-column>
        <el-table-column label="资产编号" prop="device_no" min-width="120" show-overflow-tooltip></el-table-column>
        <el-table-column label="IP" prop="ip_address" min-width="120" show-overflow-tooltip></el-table-column>
      </el-table>
      <el-pagination @current-change="handleInUseDevicesDetailCurrentChange"
        :current-page="detail.queryInfo.currentPage" :page-sizes="[detail.queryInfo.pageSize]"
        :page-size="detail.queryInfo.pageSize" layout="prev,pager,next,jumper,sizes,total" :total="detail.total">
      </el-pagination>
    </el-dialog>
  </div>

  <script src="../Scripts/echarts/echarts-5.4.0.min.js"></script>
  <script type="module">
    import { getParams, getUserWhiteList, generateUUID, exportExcelData } from '../Scripts/hooks/useCommonMethod.js';
    import { getFactory } from '../Scripts/hooks/fetchAPI.js';
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { replaceDate } from '../Scripts/hooks/format.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        replaceDate,
        loading: false,
        loadingText: '数据加载中...',
        queryInfo: { selectdate: '' },
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] },
        factoryname: '',
        dataList: [],
        factoryList: [],
        devicesMaintObj: {
          dialogVisible: false,
          dataList: [],
          queryInfo: {
            factoryname: '',
            device_no: '',
            ip_address: '',
            currentPage: 1,
            pageSize: 10
          },
          total: 0,
        },
        // 添加设备
        addDeviceObj: {
          dialogVisible: false,
          rules: {
            factoryname: [{ required: true, message: '所属分厂不能为空', trigger: 'change' }],
            device_no: [{ required: true, message: '资产编号不能为空', trigger: 'blur' }],
            ip_address: [{ required: true, message: 'IP地址不能为空', trigger: 'blur' }],
          },
          addForm: { device_no: '', factoryname: '', ip_address: '', employeeid: getParams('uid') }
        },
        // 修改设备
        updateDeviceObj: {
          dialogVisible: false,
          rules: {
            factoryname: [{ required: true, message: '所属分厂不能为空', trigger: 'change' }],
            device_no: [{ required: true, message: '资产编号不能为空', trigger: 'blur' }],
            ip_address: [{ required: true, message: 'IP地址不能为空', trigger: 'blur' }],
          },
          updateForm: { id: '', device_no: '', factoryname: '', ip_address: '', employeeid: getParams('uid') }
        },
        // 设备导入
        devicesImport: {
          dialogVisible: false,
          dataList: []
        },
        excelTemplateHeader: {
          device_no: '资产编号', factoryname: '所属分厂', ip_address: 'IP地址'
        },
        rules: { selectdate: [{ required: true, message: '筛选时间不能为空', trigger: 'change' }] },
        formDisable: false,
        detail: {
          dialogVisiable: false,
          dataList: [],
          loadingText: "数据加载中...",
          loading: false,
          queryInfo: { factoryname: '', detailType: 0, currentPage: 1, pageSize: 10 },
          total: 0,
          title: ''
        }
      },
      methods: {
        handleInUseDevicesDetailCurrentChange(newPage) {
          this.detail.queryInfo.currentPage = newPage;
          this.openDetail(this.detail.queryInfo, this.detail.queryInfo.detailType);
        },
        // 导出正在使用的设备
        exportInUseDevicesInfo() {
          const config = {
            url: '../handler/report/MESDevicesReport.ashx?action=exportInUseDevicesInfo',
            data: {
              type: 'exportInUseDevicesInfo',
              ...this.queryInfo,
              ...this.detail.queryInfo,
              title: this.detail.title
            }
          }
          exportExcelData(config, this);
        },
        async openDetail(row, detailType) {
          if (detailType == 1) {
            this.detail.title = '在用明细'
          } else {
            this.detail.title = '未用明细'
          }
          this.detail.dialogVisiable = true
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              this.detail.loading = true;
              this.detail.loadingText = '数据加载中...';
              if (this.detail.queryInfo.factoryname != row.factoryname || this.detail.queryInfo.detailType != detailType) {
                this.detail.queryInfo.currentPage = 1
                this.detail.queryInfo.factoryname = row.factoryname
                this.detail.queryInfo.detailType = detailType
              }
              const { data: { data, meta, total } } = await axios.post('../handler/report/MESDevicesReport.ashx?action=getDeviceDetail', {
                type: 'getDeviceDetail',
                ...this.queryInfo,
                ...this.detail.queryInfo,
              })
              this.detail.loading = false;
              if (meta.status === 500) { return this.$message.error(meta.msg); }
              this.detail.dataList = data;
              this.detail.total = total
            }
          })
        },
        async getData() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              this.loading = true;
              this.loadingText = '数据加载中...';
              const { data: { data, meta, total } } = await axios.post('../handler/report/MESDevicesReport.ashx?action=getData', {
                type: 'getData',
                ...this.queryInfo
              })
              this.loading = false;
              if (meta.status === 500) { return this.$message.error(meta.msg); }
              this.dataList = data;
            }
          })
        },
        // 查询已维护设备台账
        async getDevicesData() {
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post('../handler/report/MESDevicesReport.ashx?action=getDevicesData', {
            type: 'getDevicesData',
            ...this.devicesMaintObj.queryInfo
          })
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.devicesMaintObj.dataList = data;
          this.devicesMaintObj.total = total;
        },
        handleDevicesDataSearch() {
          this.devicesMaintObj.queryInfo.currentPage = 1;
          this.getDevicesData();
        },
        // 添加设备
        addDevice() {
          this.$refs["addDeviceRef"].validate(async (valid) => {
            if (valid) {
              //防止重复点击
              this.addBtnDisabled = true;
              const { data: { data, meta, total } } = await axios.post('../handler/report/MESDevicesReport.ashx?action=addDevice', {
                type: 'addDevice',
                ...this.addDeviceObj.addForm
              });

              if (meta.status === 500) { return this.$message.error(meta.msg); }

              if (total > 0) {
                this.$message.success('新增成功');
                this.addDeviceObj.dialogVisible = false;
                this.getDevicesData();
              } else {
                return this.$message.error('资产编号已存在');
              }
            }
          })
        },
        // 添加设备对话框关闭
        addDeviceClosed() {
          this.$refs["addDeviceRef"].resetFields();
        },
        // 删除设备
        async deleteDevice(id) {
          // 弹框询问用户是否删除数据
          const confirmResult = await this.$confirm('将永久次设备, 此操作无法撤销，请确认是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).catch(err => err)

          if (confirmResult !== 'confirm') { return this.$message.info('已取消删除!'); }

          const { data: { data, meta, total } } = await axios.post('../handler/report/MESDevicesReport.ashx?action=deleteDevice', {
            type: 'deleteDevice',
            id: id
          });

          if (meta.status === 500) { return this.$message.error(meta.msg); }
          if (total > 0) {
            this.$message.success('删除成功!');
            this.getDevicesData();
          } else {
            return this.$message.error('删除失败!');
          }
        },
        // 批量删除设备
        async deleteDeviceBatch() {
          const selection = this.$refs.devicesData.selection;
          if (selection.length === 0) {
            return this.$message.error('请选择待删除的数据');
          }
          const confirmResult = await this.$confirm(`将批量删除所选 ${selection.length} 条记录, 是否继续?`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).catch(err => err)
          if (confirmResult !== 'confirm') { return this.$message.info('已取消删除!'); }

          const { data: { data, meta, total } } = await axios.post('../handler/report/MESDevicesReport.ashx?action=deleteDeviceBatch', {
            type: 'deleteDeviceBatch',
            willBeDeleteData: selection
          });

          if (meta.status === 500) { return this.$message.error(meta.msg); }
          if (total > 0) {
            this.$message.success('删除成功!');
            this.devicesMaintObj.queryInfo.currentPage = 1;
            this.getDevicesData();
          } else {
            return this.$message.error('删除失败!');
          }
        },
        // 打开设备信息更新对话框
        showUpdateDeviceDialog(row) {
          this.updateDeviceObj.dialogVisible = true;
          const { id, device_no, factoryname, ip_address } = row;
          this.updateDeviceObj.updateForm = { id, device_no, factoryname, ip_address, employeeid: getParams('uid') };
        },
        // 删除设备对话框关闭
        updateDeviceClosed() {
          this.$refs["updateDeviceRef"].resetFields();
        },
        // 更新设备
        async updateDevice() {
          this.$refs["updateDeviceRef"].validate(async (valid) => {
            if (valid) {
              const { data: { data, meta, total } } = await axios.post('../handler/report/MESDevicesReport.ashx?action=updateDevice', {
                type: 'updateDevice',
                ...this.updateDeviceObj.updateForm
              });
              if (meta.status === 500) { return this.$message.error(meta.msg); }
              if (total > 0) {
                this.$message.success('更新成功');
                this.updateDeviceObj.dialogVisible = false;
                this.getDevicesData();
              } else {
                return this.$message.error('更新失败，资产编号已存在');
              }
            }
          })
        },
        // 
        devicesImportBeforeUpload(file) {
          let reader = new FileReader();
          reader.onload = e => {
            let data = new Uint8Array(e.target.result);
            let workbook = XLSX.read(data, { type: 'array' });
            let first_sheet_name = workbook.SheetNames[0];
            let worksheet = workbook.Sheets[first_sheet_name];
            let content = XLSX.utils.sheet_to_json(worksheet, { raw: false, defval: null });
            if (content.length === 0) {
              return this.$message.error('所导入的excel文件为空');
            }
            // 检验excel模板是否缺少列
            if (this.hasExcelMissingColumn(content[0])) { return; }
            let returnData = [];
            for (const i of content) {
              let item = {
                device_no: i["资产编号"],
                factoryname: i["所属分厂"],
                ip_address: i["IP地址"],
                islegel: 1,//默认校验成功
                illegalreason: '',//默认失败原因为空
                id: generateUUID() //生成唯一id
              }
              returnData.push(item);
            }
            this.devicesImport.dataList = this.validateEachRowData(returnData);
          };
          reader.readAsArrayBuffer(file);
          return false;
        },
        // 检验excel模板是否缺少列
        hasExcelMissingColumn(data) {
          return Object.values(this.excelTemplateHeader).some(i => {
            if (!(i in data)) {
              this.$message.error(`所导入的excel文件缺少【${i}】列`);
              return true;
            }
          })
        },
        // 校验所导入excel数据
        validateEachRowData(returnData) {
          for (const i of returnData) {
            if (!i.device_no) {
              i.islegel = 0;
              i.illegalreason = '资产编号不能为空';
            }
            if (!i.factoryname) {
              i.islegel = 0;
              i.illegalreason = '所属分厂不能为空';
            }
            if (!i.ip_address) {
              i.islegel = 0;
              i.illegalreason = 'IP地址不能为空';
            }
          }
          return returnData;
        },
        // 移除所选行
        async handleDelete(index, row) {
          const confirmResult = await this.$confirm('删除该行数据?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).catch(err => err)
          if (confirmResult !== 'confirm') { return this.$message.info('已取消删除!'); }
          this.devicesImport.dataList.splice(index, 1);
        },
        // 设备台账 保存数据库
        async saveDevicesImportData() {
          const selection = this.$refs.devicesImportData.selection;
          if (selection.length === 0) {
            return this.$message.error('请选择待保存的数据');
          }
          if (selection.some(i => i.islegel === 0)) {
            return this.$message.error('所选数据中存在校验失败的行！请修改校验失败的数据至正确、或将校验失败的数据删除后重试!');
          }
          this.loading = true;
          this.loadingText = '数据保存中...';
          const { data: { data, meta, total } } = await axios({
            method: 'POST',
            url: '../handler/report/MESDevicesReport.ashx?action=saveDevicesImportData',
            data: { type: 'saveDevicesImportData', willBeSavedData: selection, employeeid: getParams("uid") }
          })
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.$message.success('保存成功');
          this.devicesImport.dataList = [];
          this.devicesImport.dialogVisible = false;
        },
        // 已导入设备表格分页
        handleDevicesCurrentChange(newPage) {
          this.devicesMaintObj.queryInfo.currentPage = newPage;
          this.getDevicesData();
        },
        handleDevicesSizeChange(newSize) {
          this.devicesMaintObj.queryInfo.pageSize = newSize;
          this.getDevicesData();
        },
        async validateUser() {
          if (!getParams('uid')) {
            this.formDisable = true;
            return this.$notify.error({ title: '错误', message: '缺少用户信息!', duration: 0 });
          }
          const employeeid = getParams("uid");
          // 获取用户权限白名单
          const pageurl = window.location.pathname.split('/')[3];
          const whiteList = await getUserWhiteList(pageurl, this.$message);
          if (whiteList.indexOf(employeeid) == -1) {
            this.formDisable = true;
            this.$message.error('当前用户无权使用该功能');
          }
        }
      },
      async mounted() {
        this.factoryList = await getFactory();
        this.validateUser();
        const startOfMonth = dayjs().startOf('month').format('YYYY-MM-DD');
        const endOfMonth = dayjs().endOf('month').format('YYYY-MM-DD');
        this.queryInfo.selectdate = [startOfMonth, endOfMonth];
      },
      watch: { queryInfo: { handler() { this.queryInfo.currentPage = 1 }, deep: true } }
    })
  </script>
</body>

</html>